using FSM.IDal; 
using FSM.IBll; 
using FSM.Model; 
using SqlSugar; 
using System; 
using System.Collections.Generic; 
using System.Text; 
 
namespace FSM.Bll 
{ 
    public class SysCodeSerialBll: ISysCodeSerialBll 
    { 
        #region 模块 
        private readonly ISysCodeSerialDal dal; 
        public SysCodeSerialBll(ISysCodeSerialDal dal) 
        { 
            this.dal = dal; 
        } 
        #endregion 
 
        #region 查询 
 
        /// <summary> 
        /// 根据键值查询单个信息 
        /// </summary> 
        /// <param name="pkid">键值</param> 
        /// <returns></returns> 
        public sys_code_serial Get(int? pkid) 
        { 
            return dal.GetById(pkid); 
        } 
 
        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="code_pkid">编号键值（对应sys_code的pkid）</param> 
        /// <param name="code_pre">除流水以外的编号组全</param> 
        /// <param name="page">页码</param> 
        /// <param name="page_size">每页显示的条数</param> 
        /// <returns></returns> 
        public Tuple<List<sys_code_serial>, int> ListPagin(string code_pkid, string code_pre, int page, int page_size) 
        { 
            ISugarQueryable<sys_code_serial> queryable = dal.CreateQueryable(); 
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(code_pkid),p => p.code_pkid == code_pkid); 
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(code_pre),p => p.code_pre == code_pre); 
             
            PageModel pm = new PageModel 
            { 
                PageIndex = page, 
                PageSize = page_size 
            }; 
            Tuple<List<sys_code_serial>, int> result = dal.GetPageListAndTotal(queryable, pm); 
            return result; 
        } 
 
        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="code_pkid">编号键值（对应sys_code的pkid）</param> 
        /// <param name="code_pre">除流水以外的编号组全</param> 
        /// <returns></returns> 
        public List<sys_code_serial> List(string code_pkid, string code_pre) 
        { 
            Expressionable<sys_code_serial> queryable = Expressionable.Create<sys_code_serial>(); 
            queryable = queryable.AndIF(!string.IsNullOrEmpty(code_pkid),p => p.code_pkid == code_pkid); 
            queryable = queryable.AndIF(!string.IsNullOrEmpty(code_pre),p => p.code_pre == code_pre); 
             
            List<sys_code_serial> result = dal.GetList(queryable.ToExpression()); 
            return result; 
        } 
 
        #endregion 
 
        #region 提交 
 
        /// <summary> 
        /// 添加 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Insert(sys_code_serial model) 
        { 
            return dal.Insert(model); 
        } 
 
        /// <summary> 
        /// 更新 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Update(sys_code_serial model) 
        { 
            return dal.UpdateExcludeColumns(model) == 1; 
        } 
 
        /// <summary> 
        ///  删除 
        /// </summary> 
        /// <param name="pkid">键值</param> 
        /// <returns></returns> 
        public bool Delete(params int?[] pkid_arr) 
        { 
            return dal.Delete(pkid_arr); 
        } 
        #endregion 
    } 
} 
